package com.cn.crmsystem.service.censusService.impl;

import com.cn.crmsystem.mapper.censusMapper.SalesKitMapper;
import com.cn.crmsystem.pojo.ResultJson;

import com.cn.crmsystem.pojo.User;

import com.cn.crmsystem.service.censusService.SalesKitService;
import com.cn.crmsystem.utils.DateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;

//from ldk
@Service
public class SalesKitServiceImpl implements SalesKitService {
    @Autowired
    private SalesKitMapper salesKitMapper;

    @Override
    public ResultJson selectsaleskitcustomer(User user, String firstSelect, String secondSelect) {
        Map<String,Object> map=new HashMap<>();
        ResultJson resultJson=new ResultJson();
        List list=new ArrayList();
        if(firstSelect!=null && firstSelect.equals("nowDay")){
            map.put("nowDay", DateUtil.dateFormatString(new Date(),"yyyy-MM-dd"));
        }else if(firstSelect!=null && firstSelect.equals("nowMonth")){
            map.put("nowMonth", DateUtil.dateFormatString(new Date(),"yyyy-MM"));
        }else if(firstSelect!=null && firstSelect.equals("nowYear")){
            map.put("nowYear",DateUtil.dateFormatString(new Date(),"yyyy"));
        }else{   //2020-09-07--2020-09-08
            map.put("s_time",firstSelect.split("--")[0]);
            map.put("e_time",firstSelect.split("--")[1]);
        }
        if(secondSelect!=null && secondSelect.equals("myself")){
            map.put("userId",user.getId());
        }else  if(secondSelect!=null && secondSelect.equals("myDepartment")){
            map.put("deptId",user.getDept_id());
        }

        List<Map<String,Object>> mapListcustomer=salesKitMapper.selectsaleskitcustomer(map);//新增客户

        list.add(mapListcustomer);
        List<Map<String,Object>> mapListcontacts=salesKitMapper.selectsaleskitcontacts(map);//新增联系人
        list.add(mapListcontacts);//2
            List<Map<String,Object>> mapListopportunity =salesKitMapper.selectsaleskitopportunity (map);//新增商机
        list.add(mapListopportunity);//3
            List<Map<String,Object>> mapListcontract=salesKitMapper.selectsaleskitcontract(map);//合同
        list.add(mapListcontract);//4
            List<Map<String,Object>> mapListcontractMoney=salesKitMapper.selectsaleskitcontractMoney(map);//合同金额
        list.add(mapListcontractMoney);//5
            List<Map<String,Object>> mapListopportunityMoney=salesKitMapper.selectsaleskitopportunityMoney(map);//商机金额
        list.add(mapListopportunityMoney);//6
            List<Map<String,Object>> mapListreturnMoney=salesKitMapper.selectsaleskitreturnMoney(map);//回款金额
        list.add(mapListreturnMoney);//7
            List<Map<String,Object>> mapListfollow_upNnmber=salesKitMapper.selectsaleskitfollow_upNnmber(map);//新增跟进记录
        list.add(mapListfollow_upNnmber);//8
        if(list!=null){
         return     resultJson.getSuccess("成功",list);
        }else{
            return  resultJson.getFail("失败");
        }
    }

    @Override
    public User selectUser(Integer user_id) {
        User selectUser=salesKitMapper.selectUser(user_id);
        return  selectUser;
    }

}
